package classic150;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <h3>leetcode</h3>
 *
 * @author BigFaceCat
 * @date 2023/11/4 17:11
 * @description <p>leetcode27-移除元素-数组-简单题</p>
 */
public class No27 {
    public static void main(String[] args) {
        int[] nums = {3, 2, 2, 3};
        int val = 3;
        removeElement(nums, val);
//        for (int i = 0; i < removeElement(nums, val); i++) {
//            System.out.print(nums[i] + " ");
//        }
    }

    public static int removeElement(int[] nums, int val) {
        List<Integer> list = Arrays.stream(nums)
                                   .boxed()
                                   .filter(o -> o != val)
                                   .collect(Collectors.toList());

        for (int i = 0; i < list.size(); i++) {
            nums[i] = list.get(i);
        }

        return list.size();
    }
}